import sys

import numpy as np 
from functools import partial

from PyQt5.QtWidgets import QApplication, QMainWindow
import pyqtgraph as pg

import serial
import serial.tools.list_ports

import host_ui
from ports import Ports

def plot_curve():
    data = np.random.normal(size=10)
    pg.plot(data, title="Simplest possible plotting example")
    if sys.flags.interactive != 1 or not hasattr(QtCore, 'PYQT_VERSION'):
        pg.QtGui.QApplication.exec_()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    MainWindow = QMainWindow()
    ui = host_ui.Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    ports = Ports()

    ui.comx.addItems(ports.get_ports())
    ui.baudrate.currentIndexChanged.connect(ports.set_baudrate)
    ui.startbutton.clicked.connect(ports.init_port)
    ui.plotcurve.clicked.connect(plot_curve)

    w = ports.serial.read(3)

    sys.exit(app.exec_())

